package recursion.nowcoder.easy;

import java.util.Scanner;

/**
 * @author Stark
 * @description 和最近斐波那契数的距离
 * 题目链接:https://www.nowcoder.com/practice/18ecd0ecf5ef4fe9ba3f17f8d00d2d66?
 * tpId=85&&tqId=29846&rp=1&ru=/activity/oj&qru=/ta/2017test/question-ranking
 * @date 2022/4/25 17:22
 **/
public class ClowestToFibonacci {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int x = in.nextInt();
            int a = 1;
            int b = 1;
            int c = 2;
            while(x > c){
                c = a + b;
                a = b;
                b = c;
            }
            System.out.println(Math.min(c - x,x - a));
        }
    }
}
